import http from '../../server/ajax';

const state = {
  info: {},
};

const getters = {
  // mUser: runstate => runstate.user,
};

const mutations = {
  SetUser(runstate, user) {
    runstate.info = user || {};
  },
};

const actions = {
  login(ctx, auth) {
    return http.post('/login', auth);
  },
  register(ctx, auth) {
    return http.post('/users', auth);
  },
  getUser(ctx, token) {
    return http.get('/users/me', {
      headers: {
        'X-LC-Session': token,
      },
    }).then((user) => {
      ctx.commit('SetUser', user);
    });
  },
};
export default {
  state,
  getters,
  mutations,
  actions,
};
